import baseurl from './config'

const request = function (options) {
    try {
        const appId = uni.getStorageSync('appId')
        const token = uni.getStorageSync('token')
        if ( appId) {
            options.url = baseurl + options.url + '?appId=' + appId;
            options.header = {
                'xuanzhu-Token': token,
                'content-type': 'application/x-www-form-urlencoded',
            }
        } else {
            uni.$emit('login')
            
            return
        }
    }
    catch (err) {
        console.log(err)
    }
    return uni.request(options);
}

export default request
